package com.mgr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mgr.dao.CustomerDao;
import com.mgr.model.Customers;
import com.mgr.service.CustomerService;

@Service
public class CustomerServiceImpl implements CustomerService {
	@Autowired
	private CustomerDao customerDao;

	@Transactional
	public void add(Customers customer) {
		customerDao.add(customer);
	}

	@Transactional
	public void edit(Customers customer) {
		customerDao.edit(customer);
	}

	@Transactional
	public void delete(int custId) {
		customerDao.delete(custId);
	}

	@Transactional
	public Customers getCustomers(int custId) {
		return customerDao.getCustomers(custId);
	}

	@Transactional
	public List<Customers> getAllCustomers() {
		return customerDao.getAllCustomers();
	}

	@Transactional
	public boolean checkLogin(int id, String pass) {
		Customers cust = customerDao.getCustomers(id);

		return ((cust != null) && (cust.getCustPass().equals(pass)));
	}

	@Transactional
	public boolean verifyPassword(int id, String oldpass) {
		Customers cust = customerDao.getCustomers(id);

		return cust.getCustPass().equals(oldpass);
	}

	@Transactional
	public boolean compareNewPasswordAndConfirmPass(String newpass,
			String confirmpass) {
		return  newpass.equals(confirmpass);
	}

	@Transactional
	public void updateCustomerPass(int id, String newPass) {
		customerDao.updateCustomerPass(id, newPass);
	}

}
